package com.ibeetl.app.web;

import com.ibeetl.admin.core.rbac.UserLoginInfo;
import com.ibeetl.admin.core.service.CoreUserService;
import com.ibeetl.admin.core.web.JsonResult;
import com.ibeetl.app.service.WechatAppService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * @author bobo
 * @create 2019-10-12 17:16
 * @desc ${DESCRIPTION}
 **/
@Controller
public class WechatAppController {
    private static final String MODEL = "/wechatApp";

    @Autowired
    private WechatAppService wechatAppService;

    @Autowired
    CoreUserService userService;

    @GetMapping(MODEL + "/index.do")
    @ResponseBody
    public ModelAndView index() {
        ModelAndView view = new ModelAndView("/app/wechatApp/login.html") ;
        return view;
    }

    @GetMapping(MODEL + "/getInfo.json")
    @ResponseBody
    public JsonResult getInfo(String identity,String password,String year){
        try {
            UserLoginInfo info = userService.login(identity, password, "0");
            Map processResult = wechatAppService.getProcessResult(identity,year);
            return JsonResult.success(processResult);
        }catch (Exception e) {
            return JsonResult.fail(e.getMessage());
        }
    }
}
